Please refer to the AGB System Call Reference Manual for AGB system calls.
1) When an argument is required for the system call used, after writing to registers R0-R3 call the monitor ROM system call with the "SWI<Number>". The CPU mode changes to Supervisor Mode.
2) Save the registers, SPSR_svc (formerly CPSR), R 11, R12, LR_svc (formerly PC) to the system call stack with the monitor ROM.
3) Switch from CPU mode to system mode. Call the IRQ disable flag with monitor ROM. The previous status will continue.
4) Save the R2 and LR_usr registers to the user stack. Other registers will be saved with each system call.
5) Complete processing using each system call.
6) Return value to registers R0, R1, and R3, in cases where a system call provides a return value, and then return to the user program.
1) When an argument is required for the system call used, after reading to the registers, R0-R3, call the monitor ROM system call with the "SWI<Number>".
2) Save the registers, SPSR_svc (formerly CPSR), R12, LR_svc (formerly PC) to the system call stack with the monitor ROM.
3) Switch from CPU mode to system mode. The status of the IRQ Disable Flag prior to the call is kept in System ROM. The previous conditions will be continued.
4) Save the R2 and LR_usr registers to the user stack. Other registers will be saved with each system call.
5) Interrupt occurs while executing system call.
6) User interrupt processing is done. (You can reference the cause of the interrupt with the IF Register.) The CPU mode is changed to System Mode (User Mode with privilege) in order to solve the problem with stacks (to reference interrupt processing).
If System Call occurs during User interrupt processing, the System Call is called using Multiple Calls.
7) Monitor ROM does the system call operation (1), and loads to the system call stack.
8) Switch the CPU Mode to System Mode (privileged user mode).
9) Monitor ROM does the same operation as (3), and loads to the user stack.
10) Complete processing with each system call.
11) Return value to registers R0, R1, and R3, in cases where a system call provides a return value, and then return to the user interrupt processing.
12) Complete the user interrupt processing and return to the previous system call.
13) Complete processing with each system call.
14) Return value to registers R0, R1, and R3, in cases where a system call provides a return value, and then return to the user program.